import {request} from "@umijs/max";
import {covertTableData} from "@/utils/tableUtil";
import {ADMIN_API} from "@/services/admin/typings";


/**
 * 获取角色列表
 */
export const fetchRolePage = async (
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: { [key: string]: any },
) => {
  const resp = await request<{ records: ADMIN_API.RoleVO, total: number }>('/api/role/page', {
    method: 'GET', params: {
      ...params,
    },
    ...(options || {})
  })
  return covertTableData(resp)

}

export const saveOrUpdateRole = async (dto: ADMIN_API.RoleDTO) => {
  return request<ADMIN_API.RoleVO>('/api/role/update', {
    method: 'POST',
    data: dto
  })
}

export const saveRole = async (dto: ADMIN_API.RoleDTO) => {
  return request<ADMIN_API.RoleVO>('/api/role/save', {
    method: 'POST',
    data: dto
  })
}
export const getRoleListByUserId = async (userId: string) => {
  return request<ADMIN_API.RoleVO[]>(`/api/role/getRoleListByUserId?userId=${userId}`, {
    method: 'POST'
  })
}
